<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>子绝父相定位居中案例</title>
</head>
<style>
    .box {
        position: relative;
        /* 子绝父相 */
        margin-left: auto;
        margin-top: auto ;
        /* transform: translate(-50%,-50%); */
        width: 300px;
        height: 300px;
        background-color: pink;
    }

    .son {
        /* 1.绝对定位的盒子不能使用左右magin auto居中 */
        position: absolute;
        left: 50%;
        /* margin-left: -75px; */
        top: 50%;
        /* margin-top: -75px; */
        /* css3中进行位移的属性：自己宽度高度的一半 */
        transform: translate(-50%,-50%);
        width: 150px;
        height: 150px;
        background-color: blue;
    }
</style>

<body>
    <div class="box">
        <div class="son"></div>
    </div>
</body>

</html>